/*
 * Background Flickr: Copyright (C) 2009  Craig McNicholas
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ddw.app.bflickr.flickr.api.request;

import com.ddw.app.bflickr.flickr.api.FlickrRequest;
import com.ddw.app.bflickr.flickr.api.FlickrRequestListener;
import com.ddw.app.bflickr.flickr.api.url.FlickrApiURLFactory;
import com.ddw.app.bflickr.flickr.api.url.FlickrFindURL;
import com.ddw.app.bflickr.flickr.api.url.FlickrPhotosURL;
import com.ddw.app.bflickr.flickr.api.url.FlickrApiURLFactory.FlickrGetPhotosMethod;
import com.ddw.app.bflickr.flickr.api.url.FlickrApiURLFactory.FlickrQueryMethod;

/**
 * Factory class to generate and handle basic functionality in the 
 * flickr services api such as fetching images and conducting searches.
 * Where stated the methods are asynchronous and require the use of 
 * listening callback methods to handle responses.
 * @author craig
 *
 */
public abstract class FlickrApiRequestFactory {

	/**
	 * Method to create a flickr request object for searching the
	 * flickr services for a specific account.
	 * @param method the method used to search for the account
	 * @param apiKey the api key to pass to the flickr service for validation
	 * @param query the query to use to search for the account
	 * @param requestListener the request listener object to callback when events
	 * are raised in the request
	 * @return a flickr request object, the <i>start()</i> method must be called to 
	 * fire the request
	 */
	public static FlickrRequest createFindRequest(FlickrQueryMethod method, String apiKey, String query, FlickrRequestListener requestListener) {
		FlickrFindURL url = FlickrApiURLFactory.createQueryURL(method, apiKey, query);
		FlickrRequest req = new FlickrFindRequest(url);
		if(requestListener != null) {
			req.addListener(requestListener);
		}
		return req;
	}
	
	/**
	 * Method to create a flickr request object for searching the
	 * flickr services for a specific account.
	 * @param method the method used to search for the account
	 * @param apiKey the api key to pass to the flickr service for validation
	 * @param query the query to use to search for the account
	 * @return a flickr request object, the <i>start()</i> method must be called to 
	 * fire the request
	 */
	public static FlickrRequest createFindRequest(FlickrQueryMethod method, String apiKey, String query) {
		return createFindRequest(method, apiKey, query, null);
	}
	
	/**
	 * Method to create a flickr request object for searching for 
	 * photos that belong to a specific users account.
	 * @param apiKey the applications unique id
	 * @param NSID the users id
	 * @param requestListener the request listener object to callback when events
	 * are raised in the request
	 * @return a flickr request object, the <i>start()</i> method must be called to 
	 * fire the request
	 */
	public static FlickrRequest createPhotoRequest(String apiKey, String NSID, FlickrRequestListener requestListener) {
		FlickrPhotosURL url = FlickrApiURLFactory.createGetPhotosURL(FlickrGetPhotosMethod.FROM_USER_ID, apiKey, NSID);
		FlickrPhotosRequest req = new FlickrPhotosRequest(url);
		if(requestListener != null) {
			req.addListener(requestListener);
		}
		return req;
	}
	
	/**
	 * Method to create a flickr request object for searching for 
	 * photos that belong to a specific users account.
	 * @param apiKey the applications unique id
	 * @param NSID the users id
	 * @return a flickr request object, the <i>start()</i> method must be called to 
	 * fire the request
	 */
	public static FlickrRequest createPhotoRequest(String apiKey, String NSID) {
		return createPhotoRequest(apiKey, NSID, null);
	}
	
}
